package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.mes.domain.DeviceInfo;
import com.ruoyi.mes.domain.ProceMtr;
import com.ruoyi.mes.service.IDeviceInfoService;
import com.ruoyi.mes.service.impl.DeviceInfoServiceImpl;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.ProceInfo;
import com.ruoyi.mes.service.IProceInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工序Controller
 *
 * @author LongAndHao
 * @date 2023-04-09
 */
@RestController
@RequestMapping("/mes/proce")
public class ProceInfoController extends BaseController {
    @Autowired
    private IProceInfoService proceInfoService;

    @Autowired
    private IDeviceInfoService deviceInfoService;

    /**
     * 查询工序列表
     */
    @PreAuthorize("@ss.hasPermi('mes:proce:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProceInfo proceInfo) {
        startPage();
        List<ProceInfo> list = proceInfoService.selectProceInfoList(proceInfo);
        return getDataTable(list);
    }

    /**
     * 导出工序列表
     */
    @PreAuthorize("@ss.hasPermi('mes:proce:export')")
    @Log(title = "工序", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProceInfo proceInfo) {
        List<ProceInfo> list = proceInfoService.selectProceInfoList(proceInfo);
        ExcelUtil<ProceInfo> util = new ExcelUtil<ProceInfo>(ProceInfo.class);
        util.exportExcel(response, list, "工序数据");
    }

    /**
     * 获取工序详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:proce:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(proceInfoService.selectProceInfoById(id));
    }

    /**
     * 新增工序
     */
    @PreAuthorize("@ss.hasPermi('mes:proce:add')")
    @Log(title = "工序", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProceInfo proceInfo) {
        return toAjax(proceInfoService.insertProceInfo(proceInfo));
    }

    /**
     * 修改工序
     */
    @PreAuthorize("@ss.hasPermi('mes:proce:edit')")
    @Log(title = "工序", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProceInfo proceInfo) {
        return toAjax(proceInfoService.updateProceInfo(proceInfo));
    }

    /**
     * 删除工序
     */
    @PreAuthorize("@ss.hasPermi('mes:proce:remove')")
    @Log(title = "工序", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(proceInfoService.deleteProceInfoByIds(ids));
    }


}
